﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Aquaculture;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Aquaculture
{
    public class UpdataAquacultureCommandHandler : IRequestHandler<UpdataAquacultureCommand, ApiResult<int>>
    {

        private readonly IBaseRepository<AquacultureModel> _aquaculture;
        private readonly IMapper mapper;

        public UpdataAquacultureCommandHandler(IBaseRepository<AquacultureModel> aquaculture, IMapper mapper)
        {
            _aquaculture = aquaculture;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(UpdataAquacultureCommand request, CancellationToken cancellationToken)
        {
           
            var result=new ApiResult<int>();

            var Aquacul = mapper.Map<AquacultureModel>(request);

            _aquaculture.Update(Aquacul);
            result.data = 1;
            result.Message = "成功";
            return Task.FromResult(result);

        }
    }
}
